package com.supply.dl.activity;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.util.TypedValue;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.supply.dl.R;
import com.supply.dl.app.AppConfig;
import com.supply.dl.app.http.BaseInfo;
import com.supply.dl.bean.BaseItemBean;
import com.supply.dl.bean.EventBusImage;
import com.supply.dl.bean.InAndOutBoundLocationBean;
import com.supply.dl.bean.JobAttachBean;
import com.supply.dl.bean.JobInfoBean;
import com.supply.dl.bean.NoticeBoundDetailBean;
import com.supply.dl.bean.OperateFlagEnum;
import com.supply.dl.bean.PositionInfoBean;
import com.supply.dl.bean.SearchStockBean;
import com.supply.dl.bean.SelectDictionaryBean;
import com.supply.dl.bean.WorkInfoBean;
import com.supply.dl.bean.WorkNotesBean;
import com.supply.dl.bean.request.SaveWorkNoticeBoundDetailRequest;
import com.supply.dl.constant.Constants;
import com.supply.dl.http.HttpManger;
import com.supply.dl.utils.BigDecimalUtil;
import com.supply.dl.utils.CommonNormalAdapterUtil;
import com.supply.dl.utils.InterfaceUtil;
import com.supply.dl.utils.PhotoUtils;
import com.supply.dl.utils.RecyclerViewUtil;
import com.supply.dl.utils.StringUtils;
import com.supply.dl.utils.Utils;
import com.supply.dl.utils.utils.FileUtils;
import com.supply.dl.utils.utils.ToastUtil;
import com.supply.dl.view.MaxRecyclerView;
import com.supply.dl.widget.LoadTipFailedLayout;
import com.supply.dl.widget.adapter.CommonNormalAdapter;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;

/**
 * Created by ${qianzhihe} on 2018/5/8.
 * 通知单出库、入库详情界面
 */

public class NoticeInAndOutboundDetailsActivity extends BaseActivity{

    /**
     * 加载框
     */
    @BindView(R.id.notice_inbound_details_main_loadView)
    LoadTipFailedLayout loadTipFailedLayout;

    @BindView(R.id.notice_inbound_details_main_notWorkingTv)
    TextView notWorkingTv;//未作业
    @BindView(R.id.notice_inbound_details_main_notWorkingLineView)
    View notWorkingLineView;

    @BindView(R.id.notice_inbound_details_main_workDoneTv)
    TextView workDoneTv;//已作业
    @BindView(R.id.notice_inbound_details_main_workDoneLineView)
    View workDoneLineView;

    @BindView(R.id.notice_inbound_details_main_addNewPositionBtn)
    TextView addNewPositionBtn;//添加新定位
    @BindView(R.id.notice_inbound_details_main_batchPositionBtn)
    TextView batchPositionBtn;//批量定位

    @BindView(R.id.notice_inbound_details_main_materielLineView)
    View materielLineView;
    @BindView(R.id.notice_inbound_details_main_commonMaterielPositionInfoLayout)
    RelativeLayout commonMaterielPositionInfoLayout;

    @BindView(R.id.inbound_location_detail_main_scroll)
    ScrollView scrollAll;
    /**
     * 物料列表
     */
    @BindView(R.id.notice_inbound_details_main_materielRecyclerView)
    MaxRecyclerView materielRecyclerView;
    CommonNormalAdapter materielAdapter;
    int materielAdapterFlag;
    List<BaseItemBean> itemMaterielList;

    /**
     * 作业列表
     */
    @BindView(R.id.notice_inbound_details_main_positionRecyclerView)
    MaxRecyclerView workRecyclerView;
    CommonNormalAdapter workAdapter;
    List<BaseItemBean> itemList;
    int workAdapterFlag;

    int activityFlag;
    InAndOutBoundLocationBean mInAndOutBoundLocationBean;

    /**
     * head头部数据
     */
    @BindView(R.id.common_letter_of_notice_info_showNoticeLetterNo)
    TextView showNoticeLetterNo;
    @BindView(R.id.common_letter_of_notice_info_positionStatusName)
    TextView positionStatusName;
    @BindView(R.id.common_letter_of_notice_info_firstTv)
    TextView showFirstTv;
    @BindView(R.id.common_letter_of_notice_info_showFirstValue)
    TextView showFirstValue;
    @BindView(R.id.common_letter_of_notice_info_secondTv)
    TextView showSecondTv;
    @BindView(R.id.common_letter_of_notice_info_showSecondValue)
    TextView showSecondValue;
    @BindView(R.id.common_letter_of_notice_info_showThirdValue)
    TextView showThirdValue;
    @BindView(R.id.common_letter_of_notice_info_showFourthValue)
    TextView showFourthValue;
    @BindView(R.id.common_letter_of_notice_info_fivthTv)
    TextView showFivethTv;
    @BindView(R.id.common_letter_of_notice_info_showFivthValue)
    TextView showFivthValue;

    /**
     * 接口数据
     */
    NoticeBoundDetailBean mNoticeBoundDetailBean;
    private ArrayList<WorkInfoBean> notJobInfo;//未作业信息
    private ArrayList<WorkInfoBean> hasJobInfo;//已作业信息

    @BindView(R.id.common_materiel_position_info_showFirstValue)
    TextView showMaterielFirstValue;//物料编码
    @BindView(R.id.common_materiel_position_info_showSecondValue)
    TextView showMaterielSecondValue;//物料名称
    @BindView(R.id.common_materiel_position_info_showThirdValue)
    TextView showMaterielThirdValue;//总数
    @BindView(R.id.common_materiel_position_info_fourthTv)
    TextView materielFourthTv;
    @BindView(R.id.common_materiel_position_info_showFourthValue)
    TextView showMaterielFourthValue;//未定位数量、已定位数量

    boolean isWorkDone=false;

    int currentSelectedMaterielPosition=0;//当前物料选中的item位置
    int currentSelectedWorkPosition=0;//当前作业列表选中的item位置
    boolean isInBound;
    int itemConunt=-1;

    ArrayList<WorkNotesBean> remarks ;

    @Override
    protected int getLayoutResource() {
        return R.layout.notice_inbound_details_main;
    }

    @Override
    protected void initView() {
        super.initView();
        showLeftBack();
        setTitleShow(getResourcesString(R.string.noticeInboundDetails));
        EventBus.getDefault().register(this);
    }

    @Override
    protected void initLoadingView() {
        super.initLoadingView();
        loadTipFailedLayout.setRestartOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                refreshView();
            }
        });
    }

    private void refreshView() {
        if (activityFlag==Constants.FLAG_ACTIVITY_NOTICE_IN_BOUND_DETAILS_UI){
            isInBound=true;
        }else if(activityFlag==Constants.FLAG_ACTIVITY_NOTICE_OUT_BOUND_DETAILS_UI){
            isInBound=false;
        }
        getNoticeInAndOutBoundDetailList(isInBound);
    }

    @Override
    protected void initListener() {
        super.initListener();
        setRightHomeClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finishAllActivityExceptAppointed(MainActivity.class);
            }
        });

        setRightScanClick(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Utils.startScanActivity(NoticeInAndOutboundDetailsActivity.this);
            }
        });
        notWorkingTv.setOnClickListener(this);
        workDoneTv.setOnClickListener(this);
        addNewPositionBtn.setOnClickListener(this);
        batchPositionBtn.setOnClickListener(this);
        InterfaceUtil.getInstance().setInterfaceCallBackListener(interfacesCallBackListener);
    }

    InterfaceUtil.InterfacesCallBackListener  interfacesCallBackListener=new InterfaceUtil.InterfacesCallBackListener() {
        @Override
        public void onSuccess(BaseInfo<?> baseInfo, Enum opertateFlagEnum) {
            if (opertateFlagEnum== OperateFlagEnum.NOTICE_BOUND_DETAIL_FOR_SAVE_WORK){//保存作业
                ToastUtil.showToast(NoticeInAndOutboundDetailsActivity.this, "保存作业成功");
            }else if(opertateFlagEnum==OperateFlagEnum.NOTICE_BOUND_DETAIL_FOR_DELETE_WORK){//删除

            }
            if (!isWorkDone) {
                // 当前是未作业页面时，才执行刷新页面的操作
                refreshView();
            }
        }

        @Override
        public void onFailure(String message, Enum opertateFlagEnum) {
            if (opertateFlagEnum==OperateFlagEnum.NOTICE_BOUND_DETAIL_FOR_SAVE_WORK){

            }else if(opertateFlagEnum==OperateFlagEnum.NOTICE_BOUND_DETAIL_FOR_DELETE_WORK){

            }
            ToastUtil.showToast(NoticeInAndOutboundDetailsActivity.this, message);
        }

        @Override
        public void onSuccess(BaseInfo<?> baseInfo) {

        }

        @Override
        public void onFailure(String message) {

        }
    };

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        mInAndOutBoundLocationBean= (InAndOutBoundLocationBean) getIntent().getSerializableExtra("InAndOutBoundLocationBean");
        activityFlag=getIntent().getIntExtra(Constants.FLAG_ACTIVITY_KEY,  Constants.FLAG_ACTIVITY_NOTICE_IN_BOUND_DETAILS_UI);
        itemMaterielList=new ArrayList<>();
        itemList=new ArrayList<>();
        notJobInfo=new ArrayList<>();
        hasJobInfo=new ArrayList<>();
        remarks = new ArrayList<>();
        showFivethTv.setVisibility(View.VISIBLE);
        showFivthValue.setVisibility(View.VISIBLE);
        addNewPositionBtn.setText(getResourcesString(R.string.addNewWork));
        batchPositionBtn.setText(getResourcesString(R.string.batchWork));
        isWorkDone=false;
        isWorkDone(isWorkDone);
        if (activityFlag==Constants.FLAG_ACTIVITY_NOTICE_IN_BOUND_DETAILS_UI){
            setTitleShow(getResourcesString(R.string.noticeInboundDetails));
            showFirstTv.setVisibility(View.GONE);
            showFirstValue.setVisibility(View.GONE);
            materielAdapterFlag=CommonNormalAdapter.FLAG_NOTICE_IN_BOUND_DETAILS_MATREIEL_MAIN;
            workAdapterFlag=CommonNormalAdapter.FLAG_NOTICE_IN_BOUND_DETAILS_WORK_MAIN;
            isInBound=true;
        }else if(activityFlag==Constants.FLAG_ACTIVITY_NOTICE_OUT_BOUND_DETAILS_UI){
            setTitleShow(getResourcesString(R.string.noticeOutboundDetails));
            showSecondTv.setVisibility(View.GONE);
            showSecondValue.setVisibility(View.GONE);
            materielAdapterFlag=CommonNormalAdapter.FLAG_NOTICE_OUT_BOUND_DETAILS_MATREIEL_MAIN;
            workAdapterFlag=CommonNormalAdapter.FLAG_NOTICE_OUT_BOUND_DETAILS_WORK_MAIN;
            isInBound=false;
        }
        getNoticeInAndOutBoundDetailList(isInBound);
    }


    @Override
    protected void initRecyclerView() {
        super.initRecyclerView();
        /**
         * 物料列表
         */
        RecyclerViewUtil.initLinearLayoutHorizontal(this, materielRecyclerView);
        materielAdapter= CommonNormalAdapterUtil.initCommonNormalAdapter(R.layout.materiel_position_info_item, itemList, materielAdapterFlag);
        materielAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                showNoOrHadWorkInfo(position);
            }
        });
        materielRecyclerView.setAdapter(materielAdapter);

        /**
         * 作业列表
         */
        RecyclerViewUtil.initLinearLayoutVERTICAL(this, workRecyclerView);
        workAdapter= CommonNormalAdapterUtil.initCommonNormalAdapter(R.layout.work_info_item, itemList, workAdapterFlag);
        /**
         * 作业列表item点击事件
         * 删除点击、保存作业点击
         */
        workAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                currentSelectedWorkPosition=position;
                singleLocationItemClick(position, view);
            }
        });
        workRecyclerView.setAdapter(workAdapter);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.notice_inbound_details_main_notWorkingTv://未作业
                isWorkDone=false;
                isWorkDone(isWorkDone);
                dealWorkData(notJobInfo);
                showNoOrHadWorkInfo(0);
                break;
            case R.id.notice_inbound_details_main_workDoneTv://已作业
                isWorkDone=true;
                isWorkDone(isWorkDone);
                dealWorkData(hasJobInfo);
                showNoOrHadWorkInfo(0);
                break;
            case R.id.notice_inbound_details_main_addNewPositionBtn://添加新作业
                /**
                 * itemConunt：当前添加的itemView后的iten总数
                 */
                itemConunt++;
                addWorkItem(itemConunt);
                break;
            case R.id.notice_inbound_details_main_batchPositionBtn://批量作业
                Bundle bundle=new Bundle();
                bundle.putSerializable("InAndOutBoundLocationBean", mInAndOutBoundLocationBean);
                //操作类型(0:入库,1:出库)
                if (activityFlag==Constants.FLAG_ACTIVITY_NOTICE_IN_BOUND_DETAILS_UI){
                    bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_COME_NOTICE_LETTER_OUT_BOUND_DETAIL_UI);
                    bundle.putInt("operateType", 0);
                }else if (activityFlag==Constants.FLAG_ACTIVITY_NOTICE_OUT_BOUND_DETAILS_UI){
                    bundle.putInt(Constants.FLAG_ACTIVITY_KEY, Constants.FLAG_ACTIVITY_COME_NOTICE_LETTER_IN_BOUND_DETAIL_UI);
                    bundle.putInt("operateType", 1);
                }
                if (itemMaterielList.size()>0){
                    bundle.putSerializable("WorkInfoBean", (WorkInfoBean) itemMaterielList.get(currentSelectedMaterielPosition).object);
                }
                jumpActivity(BatchWorkActivity.class, bundle);
                break;
        }
    }

    /**
     * 添加新作业数据
     * @param itemConunt 当前列表item的总数
     */
    public void addWorkItem(final int itemConunt) {
        if (!isWorkDone){
            PositionInfoBean positionInfoBean=new PositionInfoBean();
            positionInfoBean.amount= BigDecimalUtil.getBigDecimalByString("0");
            positionInfoBean.weight= BigDecimalUtil.getBigDecimalByString("0");
            positionInfoBean.volume= BigDecimalUtil.getBigDecimalByString("0");
            positionInfoBean.actualAmount= BigDecimalUtil.getBigDecimalByString("0");
            positionInfoBean.actualWeight= BigDecimalUtil.getBigDecimalByString("0");
            positionInfoBean.actualVolume= BigDecimalUtil.getBigDecimalByString("0");
            itemList.add(new BaseItemBean(positionInfoBean));
        }else {
            JobInfoBean jobInfoBean=new JobInfoBean();
            jobInfoBean.amount= BigDecimalUtil.getBigDecimalByString("0");
            jobInfoBean.actualAmount= BigDecimalUtil.getBigDecimalByString("0");
            jobInfoBean.weight=BigDecimalUtil.getBigDecimalByString("0");
            jobInfoBean.actualWeight= BigDecimalUtil.getBigDecimalByString("0");
            jobInfoBean.volume= BigDecimalUtil.getBigDecimalByString("0");
            jobInfoBean.actualVolume= BigDecimalUtil.getBigDecimalByString("0");
            itemList.add(new BaseItemBean(jobInfoBean));
        }
        workAdapter.setNewData(itemList);
        scrollToBottom();
    }

    /**
     * 移动到列表底部
     */
    private void scrollToBottom() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                scrollAll.fullScroll(ScrollView.FOCUS_DOWN);
            }
        }, 200);
    }

    /**
     * 是否作业
     * @param isWordDone
     */
    private void isWorkDone(boolean isWordDone){
        if (!isWordDone){
            notWorkingLineView.setVisibility(View.VISIBLE);
            workDoneLineView.setVisibility(View.INVISIBLE);
            batchPositionBtn.setVisibility(View.VISIBLE);
            notWorkingTv.setTextColor(getResources().getColor(R.color.blue));
            workDoneTv.setTextColor(getResources().getColor(R.color.color_gray));
            addNewPositionBtn.setBackgroundColor(getResources().getColor(R.color.color_18C299));
        }else {
            workDoneLineView.setVisibility(View.VISIBLE);
            notWorkingLineView.setVisibility(View.INVISIBLE);
            batchPositionBtn.setVisibility(View.GONE);
            workDoneTv.setTextColor(getResources().getColor(R.color.blue));
            notWorkingTv.setTextColor(getResources().getColor(R.color.color_gray));
            addNewPositionBtn.setBackgroundColor(getResources().getColor(R.color.blue));
        }
    }

    private void getNoticeInAndOutBoundDetailList(boolean isInBound){
        loadTipFailedLayout.setLoadText(R.string.since_help_loading);
        loadTipFailedLayout.setState(LoadTipFailedLayout.STATE_PROGRESS);
        HttpManger httpManger=HttpManger.getInstance();
        httpManger.setContext(this);
        if(isInBound){
            httpManger.getNoticeInBoundDetailList(mInAndOutBoundLocationBean.noticeOrderId);
        }else {
            httpManger.getNoticeOutBoundDetailList(mInAndOutBoundLocationBean.noticeOrderId);
        }
        httpManger.setHttpResponseCallBackListener(this);
    }

    @Override
    public void onSuccess(BaseInfo<?> baseInfo) {
        super.onSuccess(baseInfo);
        mNoticeBoundDetailBean = (NoticeBoundDetailBean) baseInfo.getData();
        if (mNoticeBoundDetailBean !=null){
            loadTipFailedLayout.setState(LoadTipFailedLayout.STATE_FINISH);
            //通知单入库详情
            showNoticeLetterNo.setText(mNoticeBoundDetailBean.noticeOrderNo);//通知单订单号
            positionStatusName.setText(mNoticeBoundDetailBean.displayNodOrderStatusName);//通知单状态名称
            showFirstValue.setText(mNoticeBoundDetailBean.bussTypeName);//业务类型
            showSecondValue.setText(mNoticeBoundDetailBean.supplierName);//供应商
            showThirdValue.setText(mNoticeBoundDetailBean.carNo);//车牌号
            showFourthValue.setText(mNoticeBoundDetailBean.driverName);//司机
            showFivthValue.setText(mNoticeBoundDetailBean.remark);//备注
            if (mNoticeBoundDetailBean.getNotJobInfo()!=null){
                notJobInfo.clear();
                notJobInfo.addAll(mNoticeBoundDetailBean.getNotJobInfo());
                if (notJobInfo.size()>0){
                    for (int i=0; i<notJobInfo.size(); i++){
                        if (i==0){
                            notJobInfo.get(i).isSelected=true;
                        }else {
                            notJobInfo.get(i).isSelected=false;
                        }
                    }
                }
            }
            if (mNoticeBoundDetailBean.getHasJobInfo()!=null){
                hasJobInfo.clear();
                hasJobInfo.addAll(mNoticeBoundDetailBean.getHasJobInfo());
                if (hasJobInfo.size()>0){
                    for (int i=0; i<hasJobInfo.size(); i++){
                        if (i==0){
                            hasJobInfo.get(i).isSelected=true;
                        }else {
                            hasJobInfo.get(i).isSelected=false;
                        }
                    }
                }
            }
            dealWorkData(notJobInfo);
            showNoOrHadWorkInfo(0);
        }else {
            loadTipFailedLayout.setTextColor(R.color.color_gray);
            loadTipFailedLayout.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25);
            loadTipFailedLayout.setNormalText(R.string.noMessage);
            loadTipFailedLayout.setState(LoadTipFailedLayout.STATE_NORMAL);
        }
    }

    @Override
    public void onFailure(String message) {
        super.onFailure(message);
        loadTipFailedLayout.setTextColor(R.color.color_gray);
        loadTipFailedLayout.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
        loadTipFailedLayout.setNormalText(R.string.since_help_load_failed);
        loadTipFailedLayout.setState(LoadTipFailedLayout.STATE_FAILED);
        ToastUtil.showToast(NoticeInAndOutboundDetailsActivity.this, message);
    }

    /**
     * 处理未作业、已作业列表数据（物料）
     * @param materielWorkInfoBeanList
     */
    private void dealWorkData(ArrayList<WorkInfoBean> materielWorkInfoBeanList){
        itemMaterielList.clear();
        if (materielWorkInfoBeanList.size()>0){
            for (WorkInfoBean workInfoBean: materielWorkInfoBeanList){
                itemMaterielList.add(new BaseItemBean(workInfoBean));
            }
            setWorkUIIsShow(true);
        }else {
            setWorkUIIsShow(false);
        }
        materielAdapter.setNewData(itemMaterielList);
    }

    /**
     * 处理未作业物料item点击后，对应的作业数据
     * @param positionInfoList
     */
    private void dealPositionData(ArrayList<PositionInfoBean> positionInfoList){
        itemList.clear();
        if (positionInfoList.size()>0){
            for (PositionInfoBean positionInfoBean: positionInfoList){
                itemList.add(new BaseItemBean(positionInfoBean));
            }
            workRecyclerView.setVisibility(View.VISIBLE);
        } else {
            PositionInfoBean positionInfoBean=new PositionInfoBean();
            positionInfoBean.packageWeight= BigDecimalUtil.getBigDecimalByString("0");
            positionInfoBean.amount= BigDecimalUtil.getBigDecimalByString("0");
            positionInfoBean.weight= BigDecimalUtil.getBigDecimalByString("0");
            positionInfoBean.volume= BigDecimalUtil.getBigDecimalByString("0");
            positionInfoBean.actualAmount= BigDecimalUtil.getBigDecimalByString("0");
            positionInfoBean.actualWeight= BigDecimalUtil.getBigDecimalByString("0");
            positionInfoBean.actualVolume= BigDecimalUtil.getBigDecimalByString("0");
            itemList.add(new BaseItemBean(positionInfoBean));
        }
        workAdapter.setNewData(itemList);
        itemConunt=itemList.size();
    }

    /**
     * 处理已作业物料item点击后，对应的作业数据
     * @param jobInfoBeanList
     */
    private void dealJobInfoData(ArrayList<JobInfoBean> jobInfoBeanList){
        itemList.clear();
        if (jobInfoBeanList.size()>0){
            for (JobInfoBean jobInfoBean: jobInfoBeanList){
                itemList.add(new BaseItemBean(jobInfoBean));
            }
            workRecyclerView.setVisibility(View.VISIBLE);
        }else {
            workRecyclerView.setVisibility(View.INVISIBLE);
        }
        workAdapter.setNewData(itemList);
        itemConunt=itemList.size();
    }

    /**
     * 展示当前未作业或者已作业信息
     * @param currentPosition
     */
    private void showNoOrHadWorkInfo(int currentPosition){
        if (itemMaterielList.size()<=0){
            return;
        }
        WorkInfoBean workInfoBean= (WorkInfoBean) itemMaterielList.get(currentPosition).object;
        if (workInfoBean!=null){
            showMaterielFirstValue.setText(workInfoBean.skuCode);
            showMaterielSecondValue.setText(workInfoBean.skuName);
            showMaterielThirdValue.setText(workInfoBean.detailAmount+"件/"+workInfoBean.detailWeight+"吨");
        }

        for (BaseItemBean baseItemBean : itemMaterielList){
            ((WorkInfoBean)baseItemBean.object).isSelected=false;
        }

        ((WorkInfoBean) itemMaterielList.get(currentPosition).object).isSelected=true;
        materielAdapter.setNewData(itemMaterielList);
        if (!isWorkDone){
            materielFourthTv.setText(getResourcesString(R.string.notWorkingNumber));
            if (workInfoBean!=null){
                showMaterielFourthValue.setText(workInfoBean.notJobAmount+"件/"+workInfoBean.notJobWeight+"吨");
            }
            if (workInfoBean!=null && workInfoBean.getPositionInfoList()!=null){
                dealPositionData(workInfoBean.getPositionInfoList());
            }else {
                workRecyclerView.setVisibility(View.INVISIBLE);
            }
        }else {
            materielFourthTv.setText(getResourcesString(R.string.hasWorkingNumber));
            if (workInfoBean!=null){
                showMaterielFourthValue.setText(workInfoBean.detailAmount.subtract(workInfoBean.notJobAmount) + "件/"
                        + workInfoBean.detailWeight.subtract(workInfoBean.notJobWeight) +"吨");
            }
            if (workInfoBean!=null && workInfoBean.getJobInfoList()!=null){
                dealJobInfoData(workInfoBean.getJobInfoList());
            }else {
                workRecyclerView.setVisibility(View.INVISIBLE);
            }
        }
    }

    /**
     * 设置未作业、已作业模块是否展示
     * @param isHasData
     */
    private void setWorkUIIsShow(boolean isHasData){
        if (isHasData){
            materielRecyclerView.setVisibility(View.VISIBLE);
            materielLineView.setVisibility(View.VISIBLE);
            commonMaterielPositionInfoLayout.setVisibility(View.VISIBLE);
            workRecyclerView.setVisibility(View.VISIBLE);
        }else {
            materielRecyclerView.setVisibility(View.GONE);
            materielLineView.setVisibility(View.GONE);
            commonMaterielPositionInfoLayout.setVisibility(View.GONE);
            workRecyclerView.setVisibility(View.GONE);
        }
    }

    /**
     * 单个物料item下定位列表的item上点击事件
     * 未作业模块（单个保存作业操作）
     * @param tempCurrentSelectedWorkPosition 当前作业列表点击item的position
     * @param view
     */
    private void singleLocationItemClick(int tempCurrentSelectedWorkPosition, View view){

        EditText edtShowNumberForPiece = (EditText) workAdapter.getViewByPosition(workRecyclerView, tempCurrentSelectedWorkPosition, R.id.work_info_item_showNumberForPieceTv);
        EditText edtShowWeightForTon = (EditText) workAdapter.getViewByPosition(workRecyclerView, tempCurrentSelectedWorkPosition, R.id.work_info_item_showWeightForTonTv);
        EditText edtShowVolumeForSquare = (EditText) workAdapter.getViewByPosition(workRecyclerView, tempCurrentSelectedWorkPosition, R.id.work_info_item_showVolumeForSquareTv);

        //当前选中的物料item对象
        WorkInfoBean currentMaterielPositionInfoBean= (WorkInfoBean) itemMaterielList.get(currentSelectedMaterielPosition).object;

        String ids="";
        SaveWorkNoticeBoundDetailRequest saveWorkNoticeBoundDetailRequest=new SaveWorkNoticeBoundDetailRequest();
        saveWorkNoticeBoundDetailRequest.orderId=mInAndOutBoundLocationBean.orderId;
        saveWorkNoticeBoundDetailRequest.orderNo=mInAndOutBoundLocationBean.orderNo;
        saveWorkNoticeBoundDetailRequest.noticeOrderId=mInAndOutBoundLocationBean.noticeOrderId;
        saveWorkNoticeBoundDetailRequest.noticeOrderNo=mInAndOutBoundLocationBean.noticeOrderNo;
        saveWorkNoticeBoundDetailRequest.isActual=1;//是否是订单作业
        saveWorkNoticeBoundDetailRequest.skuId=currentMaterielPositionInfoBean.skuId;
        saveWorkNoticeBoundDetailRequest.skuCode=currentMaterielPositionInfoBean.skuCode;
        saveWorkNoticeBoundDetailRequest.skuName=currentMaterielPositionInfoBean.skuName;

        BaseItemBean baseItemBean=itemList.get(tempCurrentSelectedWorkPosition);
        if (!isWorkDone){
            PositionInfoBean positionInfoBean= (PositionInfoBean) baseItemBean.object;
            saveWorkNoticeBoundDetailRequest.orderDetailId=positionInfoBean.orderDetailId;
            saveWorkNoticeBoundDetailRequest.noticeOrderDetailId=positionInfoBean.noticeOrderDetailId;
            saveWorkNoticeBoundDetailRequest.actualStockId=positionInfoBean.stockId;
            saveWorkNoticeBoundDetailRequest.actualWhId=positionInfoBean.whId;
            saveWorkNoticeBoundDetailRequest.packageWeight=positionInfoBean.packageWeight;
            saveWorkNoticeBoundDetailRequest.actualAmount=positionInfoBean.actualAmount;
            saveWorkNoticeBoundDetailRequest.actualWeight=positionInfoBean.actualWeight;
            saveWorkNoticeBoundDetailRequest.actualVolume=positionInfoBean.actualVolume;
            saveWorkNoticeBoundDetailRequest.stockStatus=positionInfoBean.stockStatus;
            saveWorkNoticeBoundDetailRequest.stockType=positionInfoBean.stockType;
            saveWorkNoticeBoundDetailRequest.unitId=positionInfoBean.unitId;
            saveWorkNoticeBoundDetailRequest.batchNo=positionInfoBean.batchNo;
            saveWorkNoticeBoundDetailRequest.remark=positionInfoBean.remark;
            saveWorkNoticeBoundDetailRequest.invId=positionInfoBean.invId;
            ids=positionInfoBean.id;
            WorkInfoBean workInfoBean=new WorkInfoBean();
            JobAttachBean jobAttachBean=new JobAttachBean();
//            saveWorkNoticeBoundDetailRequest.setJobAmountList(positionInfoBean.getJobAmountList());
            saveWorkNoticeBoundDetailRequest.setJobAttachList(positionInfoBean.getJobAttachList());
        }else {
            JobInfoBean jobInfoBean= (JobInfoBean) baseItemBean.object;
            saveWorkNoticeBoundDetailRequest.id = jobInfoBean.id;
            saveWorkNoticeBoundDetailRequest.orderDetailId=jobInfoBean.orderDetailId;
            saveWorkNoticeBoundDetailRequest.noticeOrderDetailId=jobInfoBean.noticeOrderDetailId;
            saveWorkNoticeBoundDetailRequest.actualStockId=jobInfoBean.actualStockId;
            saveWorkNoticeBoundDetailRequest.actualWhId=jobInfoBean.actualWhId;
            saveWorkNoticeBoundDetailRequest.packageWeight=jobInfoBean.packageWeight;
            saveWorkNoticeBoundDetailRequest.actualAmount=jobInfoBean.actualAmount;
            saveWorkNoticeBoundDetailRequest.actualWeight=jobInfoBean.actualWeight;
            saveWorkNoticeBoundDetailRequest.actualVolume=jobInfoBean.actualVolume;
            saveWorkNoticeBoundDetailRequest.stockStatus=jobInfoBean.stockStatus;
            saveWorkNoticeBoundDetailRequest.stockType=jobInfoBean.stockType;
            saveWorkNoticeBoundDetailRequest.unitId=jobInfoBean.unitId;
            saveWorkNoticeBoundDetailRequest.batchNo=jobInfoBean.batchNo;
            saveWorkNoticeBoundDetailRequest.remark=jobInfoBean.remark;
            saveWorkNoticeBoundDetailRequest.invId=jobInfoBean.invId;
            ids=jobInfoBean.id;
            WorkInfoBean workInfoBean=new WorkInfoBean();
            JobAttachBean jobAttachBean=new JobAttachBean();
//            saveWorkNoticeBoundDetailRequest.setJobAmountList(jobInfoBean.getJobAmountList());
            saveWorkNoticeBoundDetailRequest.setJobAttachList(jobInfoBean.getJobAttachList());
        }
        //操作类型(0:入库,1:出库)
        if (isInBound){//入库
            saveWorkNoticeBoundDetailRequest.jobType=0;
        }else {//出库
            saveWorkNoticeBoundDetailRequest.jobType=1;
        }

        /**
         * 保存当前item编辑的数量、重量、体积数据。防止在编辑完后，选择库存状态、库存类型等其他操作返回到当前界面时，编辑的数据被刷新至初始数据
         */
        if (!isWorkDone){
            PositionInfoBean positionInfoBean= (PositionInfoBean) baseItemBean.object;
            positionInfoBean.amount=positionInfoBean.actualAmount=BigDecimalUtil.getBigDecimalByString(edtShowNumberForPiece.getText().toString());
            positionInfoBean.weight=positionInfoBean.actualWeight=BigDecimalUtil.getBigDecimalByString(edtShowWeightForTon.getText().toString());
            positionInfoBean.volume=positionInfoBean.actualVolume=BigDecimalUtil.getBigDecimalByString(edtShowVolumeForSquare.getText().toString());
//            positionInfoBean.amount=BigDecimalUtil.getBigDecimalByString(edtShowNumberForPiece.getText().toString());
//            positionInfoBean.weight=BigDecimalUtil.getBigDecimalByString(edtShowWeightForTon.getText().toString());
//            positionInfoBean.volume=BigDecimalUtil.getBigDecimalByString(edtShowVolumeForSquare.getText().toString());
        }else {
            JobInfoBean jobInfoBean= (JobInfoBean) baseItemBean.object;
            jobInfoBean.actualAmount=BigDecimalUtil.getBigDecimalByString(edtShowNumberForPiece.getText().toString());
            jobInfoBean.actualWeight=BigDecimalUtil.getBigDecimalByString(edtShowWeightForTon.getText().toString());
            jobInfoBean.actualVolume=BigDecimalUtil.getBigDecimalByString(edtShowVolumeForSquare.getText().toString());
            jobInfoBean.amount=BigDecimalUtil.getBigDecimalByString(edtShowNumberForPiece.getText().toString());
            jobInfoBean.weight=BigDecimalUtil.getBigDecimalByString(edtShowWeightForTon.getText().toString());
            jobInfoBean.volume=BigDecimalUtil.getBigDecimalByString(edtShowVolumeForSquare.getText().toString());
        }

        Intent intent =null;
        String action = "";
        int reqCode = -1;
        switch (view.getId()){
            case R.id.work_info_item_sureWorkBtn://确认该作业
                /**
                 * ids为空时，该item无数据，为新加的item
                 */
//                if (StringUtils.isEmpty(ids)){
                    if (!isWorkDone){
                        PositionInfoBean positionInfoBean= (PositionInfoBean) baseItemBean.object;
                        positionInfoBean.amount=positionInfoBean.actualAmount=BigDecimalUtil.getBigDecimalByString(edtShowNumberForPiece.getText().toString());
                        positionInfoBean.weight=positionInfoBean.actualWeight=BigDecimalUtil.getBigDecimalByString(edtShowWeightForTon.getText().toString());
                        positionInfoBean.volume=positionInfoBean.actualVolume=BigDecimalUtil.getBigDecimalByString(edtShowVolumeForSquare.getText().toString());
//                        positionInfoBean.amount=BigDecimalUtil.getBigDecimalByString(edtShowNumberForPiece.getText().toString());
//                        positionInfoBean.weight=BigDecimalUtil.getBigDecimalByString(edtShowWeightForTon.getText().toString());
//                        positionInfoBean.volume=BigDecimalUtil.getBigDecimalByString(edtShowVolumeForSquare.getText().toString());
                    }else {
                        JobInfoBean jobInfoBean= (JobInfoBean) baseItemBean.object;
                        jobInfoBean.actualAmount=BigDecimalUtil.getBigDecimalByString(edtShowNumberForPiece.getText().toString());
                        jobInfoBean.actualWeight=BigDecimalUtil.getBigDecimalByString(edtShowWeightForTon.getText().toString());
                        jobInfoBean.actualVolume=BigDecimalUtil.getBigDecimalByString(edtShowVolumeForSquare.getText().toString());
                        jobInfoBean.amount=BigDecimalUtil.getBigDecimalByString(edtShowNumberForPiece.getText().toString());
                        jobInfoBean.weight=BigDecimalUtil.getBigDecimalByString(edtShowWeightForTon.getText().toString());
                        jobInfoBean.volume=BigDecimalUtil.getBigDecimalByString(edtShowVolumeForSquare.getText().toString());
                    }
                    if (StringUtils.isEmpty(saveWorkNoticeBoundDetailRequest.actualStockId)){
                        ToastUtil.showToast(NoticeInAndOutboundDetailsActivity.this, getResourcesString(R.string.toastPleaseSeletedStockPosition));
                        return;
                    }
                    if (StringUtils.isEmpty(saveWorkNoticeBoundDetailRequest.actualWhId)){
                        ToastUtil.showToast(NoticeInAndOutboundDetailsActivity.this, getResourcesString(R.string.toastPleaseSeletedWareHouse));
                        return;
                    }

                    if (checkNumberIsEmpty(edtShowNumberForPiece, getResourcesString(R.string.toastNumberNotEmpty))){
                        return;
                    }
                    if (checkNumberIsEmpty(edtShowWeightForTon, getResourcesString(R.string.toastWeightNotEmpty))){
                        return;
                    }
                    if (checkNumberIsEmpty(edtShowVolumeForSquare, getResourcesString(R.string.toastVolumeNotEmpty))){
                        return;
                    }

                    if (checkNumberIsMoreThanZero(edtShowNumberForPiece, getResourcesString(R.string.toastNumberMustMoreThanZero))){
                        return;
                    }
                    if (checkNumberIsMoreThanZero(edtShowWeightForTon, getResourcesString(R.string.toastWeightMustMoreThanZero))){
                        return;
                    }
                    if (checkNumberIsMoreThanZero(edtShowVolumeForSquare, getResourcesString(R.string.toastVolumeMustMoreThanZero))){
                        return;
                    }
//                }
                //获取当前提交时的数量、重量、体积值
                saveWorkNoticeBoundDetailRequest.actualAmount= BigDecimalUtil.getBigDecimalByString(edtShowNumberForPiece.getText().toString());
                saveWorkNoticeBoundDetailRequest.actualWeight=BigDecimalUtil.getBigDecimalByString(edtShowWeightForTon.getText().toString());
                saveWorkNoticeBoundDetailRequest.actualVolume=BigDecimalUtil.getBigDecimalByString(edtShowVolumeForSquare.getText().toString());

                InterfaceUtil.getInstance().saveWorkNoticeBoundDetail(saveWorkNoticeBoundDetailRequest, OperateFlagEnum.NOTICE_BOUND_DETAIL_FOR_SAVE_WORK,
                        NoticeInAndOutboundDetailsActivity.this, isInBound);
                break;
            case R.id.work_info_item_workDeleteTv://删除该作业
                if (StringUtils.isEmpty(ids)){//此时该item无数据，为新增的item，故直接将列表item删除即可，无需调用接口
                    itemConunt--;
                    itemList.remove(tempCurrentSelectedWorkPosition);
                    workAdapter.setNewData(itemList);
                    return;
                }
                InterfaceUtil.getInstance().deleteLocationByNoticeLocationDetail(ids, OperateFlagEnum.NOTICE_BOUND_DETAIL_FOR_DELETE_WORK,
                        NoticeInAndOutboundDetailsActivity.this);
                break;
            case R.id.work_info_item_showReservoirPositionTv://库位选择
                intent= new Intent(this, DepotSelectActivity.class);
                if (activityFlag==Constants.FLAG_ACTIVITY_NOTICE_IN_BOUND_DETAILS_UI){
                    reqCode = AppConfig.BaseDataAction.REQCODE_NOTICE_IN_BOUND_DETAIL_BY_DEPOT;
                }else {
                    reqCode = AppConfig.BaseDataAction.REQCODE_NOTICE_OUT_BOUND_DETAIL_BY_DEPOT;
                }
                if (isInBound) {// 入库定位
                    intent.putExtra("showType", DepotSelectActivity.TYPE_IN_STOCK);
                } else {//出库定位
                    intent.putExtra("showType", DepotSelectActivity.TYPE_OUT_STOCK);
                }
                startActivityForResult(intent, reqCode);
                break;
            case R.id.work_info_item_showStorehouseTv://跳转仓库选择列表
                intent= new Intent(this, SelectBaseDataActivity.class);
                //0：入库；1：出库
                if (activityFlag==Constants.FLAG_ACTIVITY_NOTICE_IN_BOUND_DETAILS_UI){
                    action = AppConfig.BaseDataAction.WARE_HOUSE_TYPE_0;
                    reqCode = AppConfig.BaseDataAction.REQCODE_NOTICE_IN_BOUND_DETAIL;
                }else {
                    action = AppConfig.BaseDataAction.WARE_HOUSE_TYPE_1;
                    reqCode = AppConfig.BaseDataAction.REQCODE_NOTICE_OUT_BOUND_DETAIL;
                }
                intent.putExtra("action", action);
                startActivityForResult(intent, reqCode);
                break;
            case R.id.work_info_item_showInventoryStatusTv://跳转库存状态列表
                intent = new Intent(this, SelectBaseDataActivity.class);
                action = AppConfig.BaseDataAction.STO_INVENTORY_STOCK_STATUS;
                reqCode = AppConfig.BaseDataAction.REQCODE_STO_INVENTORY_STOCK_STATUS;
                intent.putExtra("action", action);
                startActivityForResult(intent, reqCode);
                break;
            case R.id.work_info_item_showInventoryTypeTv://跳转库存类型列表
                intent = new Intent(this, SelectBaseDataActivity.class);
                action = AppConfig.BaseDataAction.STO_INVENTORY_STOCK_TYPE;
                reqCode = AppConfig.BaseDataAction.REQCODE_STO_INVENTORY_STOCK_TYPE;
                intent.putExtra("action", action);
                startActivityForResult(intent, reqCode);
                break;
            case R.id.work_info_item_showJobRecordTv://作业记录
                intent = new Intent(this, OperateRemarkActivity.class);
                startActivityForResult(intent, AppConfig.BaseDataAction.REQCODE_JOB_RECORD);
                break;
            case R.id.work_info_item_showStandardTv://规格
                intent = new Intent(this, SelectBaseDataActivity.class);
                action = AppConfig.BaseDataAction.WARE_SELECT_SKU_UNIT;
                reqCode = AppConfig.BaseDataAction.REQCODE_SKU_UNIT;
                intent.putExtra("action", action);
                intent.putExtra("skuId", currentMaterielPositionInfoBean.skuId);//物料ID
                startActivityForResult(intent, reqCode);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                //拍照完成回调
                case CODE_CAMERA_REQUEST:
                    displayImage(FileUtils.getRealFilePathToUri(NoticeInAndOutboundDetailsActivity.this, imageUri));
//                    cropImageUri = Uri.fromFile(fileCropUri);
//                    PhotoUtils.cropImageUri(this, imageUri, cropImageUri, 1, 1, OUTPUT_X, OUTPUT_Y, CODE_RESULT_REQUEST);
                    break;
                //访问相册完成回调
                case CODE_GALLERY_REQUEST:
                    if (hasSdcard()) {
                        Uri newUri = Uri.parse(PhotoUtils.getPath(this, data.getData()));
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                            newUri = FileProvider.getUriForFile(this, "com.supply.dl", new File(newUri.getPath()));
                        }
                        displayImage(FileUtils.getRealFilePathToUri(NoticeInAndOutboundDetailsActivity.this, newUri));
//                        cropImageUri = Uri.fromFile(fileCropUri);
//                        PhotoUtils.cropImageUri(this, newUri, cropImageUri, 1, 1, OUTPUT_X, OUTPUT_Y, CODE_RESULT_REQUEST);
                    } else {
                        ToastUtil.showToast(this, "设备没有SD卡！");
                    }
                    break;
                case CODE_RESULT_REQUEST:
                    //displayImage(FileUtils.getRealFilePathToUri(NoticeInAndOutboundDetailsActivity.this, cropImageUri));
                    break;
            }
        }

        if (requestCode==HEAD_ABLUME | requestCode==HEAD_CAREAM){
            switch (requestCode){
                case HEAD_ABLUME://相册返回
                    // 判断手机版本，因为在4.4版本都手机处理图片返回的方法就不一样了
                    //4.4以后返回的不是真实的uti而是一个封装过后的uri 所以要对封装过后的uri进行解析
                    if (data!=null){
                        if (Build.VERSION.SDK_INT >= 19) {
                            //4.4系统一上用该方法解析返回图片
                            displayImage(handleImageOnKitKat(data));
                        } else {
                            //4.4一下用该方法解析图片的获取
                            displayImage(handleImageBeforeKitKat(data));
                        }
                    }
                    break;
                case HEAD_CAREAM://相机
                    if (data!=null){
                        Bundle bundle=data.getExtras();
                        if (bundle!=null){//照相后，点击取消时，该bundle为空
                            Bitmap bitmap= (Bitmap) bundle.get("data");
                            String fileName= FileUtils.saveImage(bitmap);//保存照相的图片
                            Uri uri=Uri.fromFile(FileUtils.getFile(fileName));
                            displayImage(FileUtils.getRealFilePathToUri(NoticeInAndOutboundDetailsActivity.this, uri));
                        }
                    }
                    break;
            }
            return;
        }

        BaseItemBean baseItemBean=itemList.get(currentSelectedWorkPosition);
        /**
         * 获取作业记录数据
         */
        if (data != null && requestCode == AppConfig.BaseDataAction.REQCODE_JOB_RECORD) {
            remarks = (ArrayList<WorkNotesBean>) data.getSerializableExtra("remarks");
            if (remarks.size() > 0) {
                String workNoteName = "";
                for (int i = 0; i < remarks.size(); i++) {
                    if (StringUtils.isBlank(workNoteName))
                        workNoteName = remarks.get(i).getDepart();
                    else
                        workNoteName = workNoteName + "," + remarks.get(i).getDepart();
                }
                if (!isWorkDone){
                    PositionInfoBean positionInfoBean= (PositionInfoBean) baseItemBean.object;
                    positionInfoBean.jobRecord=workNoteName;
                    baseItemBean.object=positionInfoBean;
                }else {
                    JobInfoBean jobInfoBean= (JobInfoBean) baseItemBean.object;
                    jobInfoBean.jobRecord=workNoteName;
                    baseItemBean.object=jobInfoBean;
                }
                workAdapter.notifyItemChanged(currentSelectedWorkPosition);
            }
            return;
        }
        /**
         * 获取库存状态、库存类型等数据
         */
        if (data == null || data.getSerializableExtra("selectBean") == null)
            return;
        switch (requestCode){
            case AppConfig.BaseDataAction.REQCODE_NOTICE_IN_BOUND_DETAIL:
            case AppConfig.BaseDataAction.REQCODE_NOTICE_OUT_BOUND_DETAIL:
                SelectDictionaryBean selectBean = (SelectDictionaryBean) data.getSerializableExtra("selectBean");
                if (!isWorkDone){
                    PositionInfoBean positionInfoBean= (PositionInfoBean) baseItemBean.object;
                    positionInfoBean.whName=selectBean.getText();
                    positionInfoBean.whId=selectBean.getValue();
                    positionInfoBean.actualWhId=selectBean.getValue();
                    baseItemBean.object=positionInfoBean;
                }else {
                    JobInfoBean jobInfoBean= (JobInfoBean) baseItemBean.object;
                    jobInfoBean.whName=selectBean.getText();
                    jobInfoBean.whId=selectBean.getValue();
                    jobInfoBean.actualWhId=selectBean.getValue();
                    baseItemBean.object=jobInfoBean;
                }
                workAdapter.notifyItemChanged(currentSelectedWorkPosition);
                break;
            case AppConfig.BaseDataAction.REQCODE_NOTICE_IN_BOUND_DETAIL_BY_DEPOT:
            case AppConfig.BaseDataAction.REQCODE_NOTICE_OUT_BOUND_DETAIL_BY_DEPOT:
                SearchStockBean searchStockBean= (SearchStockBean) data.getSerializableExtra("selectBean");
                if (!isWorkDone){
                    PositionInfoBean positionInfoBean= (PositionInfoBean) baseItemBean.object;
                    positionInfoBean.stockName=searchStockBean.getStockName();
                    positionInfoBean.stockId=searchStockBean.getStockId();
                    positionInfoBean.actualStockId=searchStockBean.getStockId();
                    positionInfoBean.whName=searchStockBean.getWhName();
                    positionInfoBean.whId=searchStockBean.getWhId();
                    positionInfoBean.actualWhId=searchStockBean.getWhId();
                    positionInfoBean.invId=searchStockBean.getId();

                    if (!isInBound) {// 出库定位
                        positionInfoBean.stockStatusName=searchStockBean.getStockStatusName();
                        positionInfoBean.stockStatus=searchStockBean.getStockStatus();
                        positionInfoBean.stockTypeName=searchStockBean.getStockTypeName();
                        positionInfoBean.stockType=searchStockBean.getStockType();
                        positionInfoBean.unitName=searchStockBean.getUnitName();
                        positionInfoBean.unitId=searchStockBean.getUnitId();
                        positionInfoBean.batchNo=searchStockBean.getBatchNo();
                    }
                    baseItemBean.object=positionInfoBean;
                }else {
                    JobInfoBean jobInfoBean= (JobInfoBean) baseItemBean.object;
                    jobInfoBean.stockName=searchStockBean.getStockName();
                    jobInfoBean.stockId=searchStockBean.getStockId();
                    jobInfoBean.actualStockId=searchStockBean.getStockId();
                    jobInfoBean.whName=searchStockBean.getWhName();
                    jobInfoBean.whId=searchStockBean.getWhId();
                    jobInfoBean.actualWhId=searchStockBean.getWhId();
                    jobInfoBean.actualWhName=searchStockBean.getWhName();
                    jobInfoBean.invId=searchStockBean.getId();

                    if (!isInBound) {// 出库定位
                        jobInfoBean.stockStatusName=searchStockBean.getStockStatusName();
                        jobInfoBean.stockStatus=searchStockBean.getStockStatus();
                        jobInfoBean.stockTypeName=searchStockBean.getStockTypeName();
                        jobInfoBean.stockType=searchStockBean.getStockType();
                        jobInfoBean.unitName=searchStockBean.getUnitName();
                        jobInfoBean.unitId=searchStockBean.getUnitId();
                        jobInfoBean.batchNo=searchStockBean.getBatchNo();
                    }
                    baseItemBean.object=jobInfoBean;
                }
                workAdapter.notifyItemChanged(currentSelectedWorkPosition);
                break;
            case AppConfig.BaseDataAction.REQCODE_STO_INVENTORY_STOCK_STATUS://库存状态
                selectBean= (SelectDictionaryBean) data.getSerializableExtra("selectBean");
                if (!isWorkDone){
                    PositionInfoBean positionInfoBean= (PositionInfoBean) baseItemBean.object;
                    positionInfoBean.stockStatusName=selectBean.getText();
                    positionInfoBean.stockStatus=selectBean.getValue();
                    baseItemBean.object=positionInfoBean;
                }else {
                    JobInfoBean jobInfoBean= (JobInfoBean) baseItemBean.object;
                    jobInfoBean.stockStatusName=selectBean.getText();
                    jobInfoBean.stockStatus=selectBean.getValue();;
                    baseItemBean.object=jobInfoBean;
                }
                workAdapter.notifyItemChanged(currentSelectedWorkPosition);
                break;
            case AppConfig.BaseDataAction.REQCODE_STO_INVENTORY_STOCK_TYPE://库存类型
                selectBean= (SelectDictionaryBean) data.getSerializableExtra("selectBean");
                if (!isWorkDone){
                    PositionInfoBean positionInfoBean= (PositionInfoBean) baseItemBean.object;
                    positionInfoBean.stockTypeName=selectBean.getText();
                    positionInfoBean.stockType=selectBean.getValue();
                    baseItemBean.object=positionInfoBean;
                }else {
                    JobInfoBean jobInfoBean= (JobInfoBean) baseItemBean.object;
                    jobInfoBean.stockTypeName=selectBean.getText();;
                    jobInfoBean.stockType=selectBean.getValue();
                    baseItemBean.object=jobInfoBean;
                }
                workAdapter.notifyItemChanged(currentSelectedWorkPosition);
                break;
            case AppConfig.BaseDataAction.REQCODE_SKU_UNIT://规格
                selectBean= (SelectDictionaryBean) data.getSerializableExtra("selectBean");
                if (!isWorkDone){
                    PositionInfoBean positionInfoBean= (PositionInfoBean) baseItemBean.object;
                    positionInfoBean.unitName=selectBean.getText();
                    positionInfoBean.unitId=selectBean.getValue();
                    baseItemBean.object=positionInfoBean;
                }else {
                    JobInfoBean jobInfoBean= (JobInfoBean) baseItemBean.object;
                    jobInfoBean.unitName=selectBean.getText();
                    jobInfoBean.unitId=selectBean.getValue();
                    baseItemBean.object=jobInfoBean;
                }
                workAdapter.notifyItemChanged(currentSelectedWorkPosition);
                break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    /**
     * 校验数量、重量、体积是否为空
     * @param editText
     * @param message
     */
    private boolean checkNumberIsEmpty(EditText editText, String message){
        if (StringUtils.isEmpty(editText.getText().toString())){
            ToastUtil.showToast(NoticeInAndOutboundDetailsActivity.this, message);
            return true;
        }
        return false;
    }

    /**
     * 校验数量、重量、体积是否大于0
     * @param editText
     * @param message
     */
    private boolean checkNumberIsMoreThanZero(EditText editText, String message){
        if (Float.parseFloat(editText.getText().toString())<=0){
            ToastUtil.showToast(NoticeInAndOutboundDetailsActivity.this, message);
            return true;
        }
        return false;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(final EventBusImage eventBusImage){
        currentSelectedWorkPosition=eventBusImage.currentItemPosition;
        openAblumeOrCaream(eventBusImage.flag);
    }

    /**
     * 打开相册或者相机
     * @param flag
     */
    private void openAblumeOrCaream(int flag){
        switch (flag){
            case HEAD_ABLUME://相册
                autoObtainStoragePermission();
//                Intent intent = new Intent();
//                intent.setType("image/*");
//                intent.setAction(Intent.ACTION_GET_CONTENT);
//                startActivityForResult(intent, HEAD_ABLUME);
                break;
            case HEAD_CAREAM://相机
                autoObtainCameraPermission();
//                Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//                startActivityForResult(camera, HEAD_CAREAM);
                break;
        }
    }

    /**
     * 通过imagepath来绘制immageview图像
     *
     * @param imagPath
     */
    protected void displayImage(String imagPath) {
        if (imagPath != null) {
//            Bitmap bitmap = BitmapFactory.decodeFile(imagPath);
//            bean.setBitmap(bitmap);
            JobAttachBean jobAttachBean=new JobAttachBean();
            jobAttachBean.attachUrl=imagPath;
            ArrayList<JobAttachBean> imageList=new ArrayList<>();
            imageList.add(jobAttachBean);
            BaseItemBean baseItemBean=itemList.get(currentSelectedWorkPosition);
            if (!isWorkDone){
                PositionInfoBean positionInfoBean= (PositionInfoBean) baseItemBean.object;
                positionInfoBean.imagePath=imagPath;
                positionInfoBean.setJobAttachList(imageList);
                baseItemBean.object=positionInfoBean;
            }else {
                JobInfoBean jobInfoBean= (JobInfoBean) baseItemBean.object;
                jobInfoBean.setJobAttachList(imageList);
                jobInfoBean.imagePath=imagPath;
                baseItemBean.object=jobInfoBean;
            }
            workAdapter.notifyItemChanged(currentSelectedWorkPosition);
        } else {
            ToastUtil.showToast(this, "图片获取失败");
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

}
